<html>
  <head>
  </head>
  <body>
    Type a SQL query into the following box:</br>
	<form method="GET" action="query.php">
		<textarea rows="8" cols="60" name="query"></textarea>
		<input type="submit" value = "Submit" />
	</form>

	<b>Results from MySQL:</b></br>

	<?php
		$query = $_GET["query"];
		if($query != NULL){
			$db_connection = mysql_connect("localhost", "cs143", "");
			mysql_select_db("CS143", $db_connection);
			$rs = mysql_query($query, $db_connection);

			print "<table border='1' width='400'>";

			while($row = mysql_fetch_row($rs)) {
				$numrows = count($row);
				print "<tr>";
				foreach($row as $field) {
					print "<td>";
          print ($field == NULL) ? "N/A" : $field;
					print "</td>";
				}
				print "</tr>";
			}
			print "</table>";
			mysql_close($db_connection);
		}
	?>
  </body>
</html>

